package cn.example.game.config;

import cn.example.game.plugins.storage.StoragePluginFactory;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.setting.Setting;
import org.artifact.core.context.id.SnowflakeFactory;
import org.artifact.core.lang.IConfig;
import org.artifact.core.lang.IContext;
import org.artifact.core.lang.Plugins;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;

public class GameConfig implements IConfig {
    @Override
    public void configContext(IContext me) {
        // 初始化Spring
        me.setSpringContext(new ClassPathXmlApplicationContext("app-init.xml"));

        // 设置配置文件
        me.setSetting(new Setting("app.properties"));

        // Redis连接池
        //me.setRedisDS(new RedisDS(me.getSetting(),null));

        me.setDataSource(me.getSpringContext().getBean("dataSource", DataSource.class));

        // 设置ID工厂
        me.setIdFactory(new SnowflakeFactory(new Snowflake(0, 0)));

        //me.setSessionFactory(new NettySessionFactory());
    }

    @Override
    public void configPlugin(Plugins me) {
        // 定时入库插件
        me.add(new StoragePluginFactory());
    }

    @Override
    public void afterServerStart() {

    }

    @Override
    public void beforeServerStop() {

    }
}
